package cn.huiyunche.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.huiyunche.base.service.interfaces.impl.MenuServiceImpl;
import cn.huiyunche.base.service.model.SysAdminMenu;
import cn.huiyunche.base.service.vo.Result;
import cn.huiyunche.base.service.vo.SysAdminMenuVo;

/**
 * 菜单控制器
 * @author hdy [Tuffy]
 *
 */
@Controller
@RequestMapping("/menu")
public class MenuController {

	@Autowired
	private MenuServiceImpl menuServiceImpl = null;
	
	@RequestMapping(method= RequestMethod.GET)
	@ResponseBody
	public Result<List<SysAdminMenuVo>> bannerMenu(Long bannerId) {
		return this.getMenuServiceImpl().bannerMenu(bannerId);
	}
	
	@RequestMapping(value = "/all", method= RequestMethod.GET)
	@ResponseBody
	public Result<List<SysAdminMenuVo>> allMenu() {
		return this.getMenuServiceImpl().allMenu();
	}
	
	@RequestMapping(value = "/{id}", method= RequestMethod.GET)
	@ResponseBody
	public Result<SysAdminMenuVo> byId(@PathVariable Long id) {
		return this.getMenuServiceImpl().byId(id);
	}
	
	@RequestMapping(value = "/delete", method= RequestMethod.POST)
	@ResponseBody
	public Result<String> removeMenu(Long id) {
		return this.getMenuServiceImpl().removeMenu(id);
	}
	
	@RequestMapping(value = "/edit", method= RequestMethod.POST)
	@ResponseBody
	public Result<String> saveMenu(SysAdminMenu sam, String roleIds) {
		return this.getMenuServiceImpl().saveMenu(sam, roleIds);
	}
	
	@RequestMapping(value = "/level/{id}", method= RequestMethod.GET)
	@ResponseBody
	public Result<List<SysAdminMenu>> parentIds(@PathVariable Long id) {
		return this.getMenuServiceImpl().getParentIdList(id);
	}
	
	private MenuServiceImpl getMenuServiceImpl() {
		return this.menuServiceImpl;
	}
}
